home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * ObjectMacZapp -- a standard Mac OOP application template
- *
- *
- *
- * ZAdvancedDialog.h -- a dialog box that can be extended with new types of items.
- * this will handle list boxes without subclassing.
- *
- *
- * © 1997, Graham Cox
- *
- *
- *
- *************************************************************************************************/
-
- #pragma once
-
- #ifndef __ZADVANCEDDIALOG__
- #define __ZADVANCEDDIALOG__
-
-
- #include "ZDialog.h"
- #include "ZObjectArray.h"
- #include <Lists.h>
-
- class ZDialogItem;
-
-
- typedef ZObjectArray<ZDialogItem> ZDialogItemList;
-
- typedef enum
- {
- typeStaticText = statText,
- typeEditText = editText,
- typeIcon = iconItem,
- typePicture = picItem,
- typeButton = btnCtrl,
- typeCheckBox = chkCtrl,
- typeRadioButton = radCtrl,
- typeResControl = resCtrl,
- typeUserItem = 'user',
- typeListBox = 'list',
- typeLine = 'line',
- type3DLine = '3dln',
- typeIconList = 'icls'
- }
- ItemType;
-
-
- // generic item class:
-
- class ZDialogItem : public ZCommander
- {
- protected:
- short id; // dialog item ID
- ItemType type; // item type
- Handle iHand; // original item handle
- Rect bounds; // bounding box
- Boolean enabled; // TRUE if item enabled for clicks
- Boolean canBeHandler; // TRUE if this item can become part of the cmd chain
- Boolean isHandler; // TRUE if currently is the handler for typing, etc.
-
- public:
- ZDialogItem( ZDialog* aDialog, short item );
- virtual ~ZDialogItem() {};
-
- virtual void DrawItem() { FrameRect( &bounds ); };
- virtual void ClickItem( const Point where, const short modifiers ) {};
- virtual void AdjustCursor( const Point where, const short modifiers ) { SetCursor( &qd.arrow ); };
- virtual void InitItem( const long param1, const long param2 ) {};
- virtual void DrawBorder( Boolean bState );
- virtual void Activate( const Boolean isActive ) {};
- virtual void Idle() {};
-
- virtual void SetCanBeHandler( Boolean hState ) { canBeHandler = hState; };
- virtual void BecomeHandler( Boolean isBecoming );
-
- inline ItemType GetType() { return type; };
- inline Boolean ContainsPoint( Point where ) { return PtInRect( where, &bounds ); };
- inline short GetID() { return id; };
- inline Boolean Enabled() { return enabled; };
- inline Boolean CanBeHandler() { return canBeHandler; };
- };
-
- // messages sent by items when they change focus
-
- enum
- {
- ItemNowHandler = 'ich+',
- ItemNoLongerHandler = 'ich-'
- };
-
- // lists can be constructed from resource templates. Here is the definition for
- // the template:
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- typedef struct
- {
- short rows; // number of rows
- short columns; // number of columns
- short stringsListID; // ID number of STR# resource to fill list with
- short procID; // LDEF proc ID (0 for standard)
- Boolean hasVertScroll : 1; // TRUE if has vertical scrollbar
- Boolean hasHorizScroll : 1; // TRUE if has horizontal scrollbar
- Boolean hasGrowBox : 1; // TRUE if has grow box
- Boolean visible : 1; // TRUE if initially visible
- Boolean keyboardNav : 1; // TRUE if can have the keyboard focus
- long refCon; // reference constant
- short fontSize; // size of font to use (uses window font if 0).
- Str63 fontName; // which font to use.
- }
- ListTemplate, *ListTemplatePtr, **ListTemplateHdl;
-
-
- #define kListTemplateResType 'LIST'
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- // subclass of item to handle list box item
-
- class ZListDialogItem : public ZDialogItem
- {
- protected:
- ListHandle theList; // the list manager list
- Cell lastSel; // cell selected when deactivated
- Str15 searchStr; // for finding items in a list
- long lastKeyTime; // time last key was typed
- short fThresh; // reset threshold for typing
- short font; // which font
- short fontSize; // what size font
- short strListID; // ID of string list to use
-
- public:
- ZListDialogItem( ZDialog* aDialog, const short item );
- ~ZListDialogItem();
-
- virtual void DrawItem();
- virtual void ClickItem( const Point where, const short modifiers );
- virtual void InitItem( const long param1, const long param2 );
- virtual void Type( const char theKey );
- virtual void BecomeHandler( Boolean isBecoming );
- virtual void Activate( const Boolean isActive );
- virtual void SetUpFontForList( short* curFont, short* curSize );
- virtual void UpdateMenus() {};
- virtual void AppendString( Str255 aString, Boolean drawIt = TRUE );
-
- inline ListHandle GetMacList() { return theList; };
-
- protected:
- virtual void MakeMacList( const short listTemplateID = 0 );
- virtual void ActivateListItem( const Boolean state );
- };
-
- // message sent from list box when a new item is selected
-
- enum
- {
- newListItemSelected = 'lstc',
- listItemDoubleClicked = 'lsdb'
- };
-
-
- // advanced dialog class:
-
- class ZAdvancedDialog : public ZDialog
- {
- protected:
- ZDialogItemList* itsItems; // list of special object items
- ZDialogItem* curHandler; // object that has keyboard focus
- short focusItem; // item ID that has focus, including real items
-
- public:
- ZAdvancedDialog( ZCommander* aBoss, const short dialogID );
- ~ZAdvancedDialog();
-
- virtual void SetUp();
- virtual void ClickItem( const short item );
- virtual void DrawUserItem( const short item );
- virtual Boolean HasMultipleFoci();
- virtual void SelectItem( const short item );
- virtual void AdjustCursor( const Point mouse, const short modifiers );
- virtual void Deactivate();
- virtual void Activate();
- virtual void Type( const char theKey );
- virtual ZDialogItem* GetObjectItem( const short item );
- virtual ZCommander* GetHandler();
-
- protected:
- virtual void ParseStatTextPseudoObjects( Str255 sText,
- long* typeParam,
- long* param1,
- long* param2 );
- virtual void BuildItemList();
-
- virtual ZDialogItem* MakeObjectItem( const long aType, const short id );
- virtual ZDialogItem* FindObjectItem( const Point where );
- virtual void HiliteDialogText( Boolean state );
- virtual Boolean SelectNextFocus();
- virtual void ReceiveMessage( ZComrade* aSender, long aMessage, void* msgData );
- };
-
-
- extern UserItemUPP gUIVectorUPP;
-
- // this dialog class can do everything an ordinary dialog can, but in addition can display list-manager
- // lists. By default, the lists are set up with strings obtained from a STR# resource. This functionality
- // is based on an embryonic general dialog enhancement technique that will be further developed once we
- // know what sort of things are needed. In the meantime, this will handle list manager list boxes without
- // further subclassing.
-
- // How this works is through the use of pseudo-items in the DITL template. These are declared as static
- // text items, but containing a special string sequence that this object parses and converts to other
- // object-based items. The strings must start with two dollar signs followed by the name of the object
- // then followed by a comma-delimited parameter list. e.g. "$$LIST,128,0". When this object encounters
- // this, it will a) convert the item to a user item and set up a drawing procedure for it via an object
- // of type ZDialogItem, b) extract the parameters and pass them to the item's initialiser, c) handle
- // clicks, etc in the item.
-
- // Though apparently complex, this is a very powerful and easy to use feature once you get the hang of
- // it, requiring nothing more than setting up your DITL and making this object with it.
-
- #endif